package com.central.scheduler.common.entity;

import com.central.common.entity.TaskContent;
import com.central.common.enums.TaskType;
import com.central.common.properties.Property;
import com.central.scheduler.common.Constants;
import com.central.scheduler.common.enums.Priority;
import com.central.scheduler.common.enums.TaskTimeoutStrategy;
import com.central.scheduler.common.task.AbstractParameters;
import com.central.scheduler.common.task.TaskTimeoutParameter;
import com.central.scheduler.common.utils.JSONUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tindy
 * @date 2021/11/5
 * @describe
 */
@Getter
@Setter
public class TaskNode {

    /**
     * task node taskDefinitionId
     */
    private Long taskDefinitionId;

    /**
     * task node taskDefinedLogId
     */
    private Long taskDefinedLogId;

    /**
     * task node version
     */
    private int version;

    /**
     * task node name
     */
    private String name;

    /**
     * task node description
     */
    private String desc;

    /**
     * task node type
     */
    private TaskType type;

    /**
     * the run flag has two states, NORMAL or FORBIDDEN
     */
    private String runFlag;

    /**
     * maximum number of retries
     */
    private int maxRetryTimes;

    /**
     * Unit of retry interval: points
     */
    private int retryInterval;

    private List<Long> resourceIds;

    private String taskContent;

    /**
     * local params information
     */
    private List<Property> localParams;

    /**
     * node dependency list
     */
    private List<String> depList;

    /**
     * outer dependency information
     */
    private AbstractParameters relationParameters;

    /**
     * task instance priority
     */
    private Priority taskInstancePriority;

    /**
     * worker group
     */
    private Long workerGroupId;

    /**
     * environment id
     */
    private Long environmentId;

    /**
     * task time out
     */
    private TaskTimeoutParameter timeout;

    /**
     * delay execution time.
     */
    private int delayTime;

    public void setDepList(List<String> depList) {
        this.depList = depList;
    }
    public List<String> getDepList() {
        return this.depList;
    }

    public Boolean isForbidden() {
        return (!StringUtils.isEmpty(this.runFlag)
                && this.runFlag.equals(Constants.FLOWNODE_RUN_FLAG_FORBIDDEN));
    }


    public boolean isConditionsTask() {
        return TaskType.CONDITIONS.equals(this.getType());
    }

    public boolean isSwitchTask() {
        return TaskType.SWITCH.equals(this.getType());
    }

}
